<?php

class TpropertyModel extends Model{
	
	public $table='tproperty';
	
	public $validate=array(
		
		array('tpname','nonull','属性名称不能为空',2,3),
		array('tpvalue','nonull','属性值不能为空',2,3),
		
	);
	
	public function get_all_data($where=null){
		
		return $this->where($where)->all();
	}
	
	
	public function add_data(){
		
		if(!$this->create()) return FALSE;
		$preg="/[\n\r]+/";
		$tpvalue=preg_replace($preg, ',', Q('post.tpvalue'));
		$tpvalue=rtrim($tpvalue,',');
//		p($tpvalue);die;
			$data=array(
				'tid'=>Q('get.tid'),
				'tpname'=>Q('post.tpname'),
				'tptype'=>Q('post.tptype'),
				'tpvalue'=>$tpvalue,
			);	
		
		return $this->add($data);
	}
	
	public function delete_data($where=null){
		
		return $this->where($where)->delete();
	}
	
	public function get_one_data($where=null){
		return $this->where($where)->find();
	}
	
	public function edit_data($where=null){
		
		if(!$this->create()) return FALSE;
		$preg="/[\n\r]+/";
		$tpvalue=preg_replace($preg, ',', Q('post.tpvalue'));
		$tpvalue=rtrim($tpvalue,',');
//		p($tpvalue);die;
			$data=array(
				'tpname'=>Q('post.tpname'),
				'tptype'=>Q('post.tptype'),
				'tpvalue'=>$tpvalue,
			);
		return $this->where($where)->update($data);
	}
	
	public function get_tpname($where=null){
		
		return $this->where($where)->getField('tpname');
	}
	
}






